package com.yesido.split.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yesido.split.mapper.UserMapper;
import com.yesido.split.pojo.MyPage;
import com.yesido.split.pojo.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yesido
 * @description 测试类
 * @date 2023-06-14 23:37
 * @Version 8.3
 */
@RestController
@RequestMapping("split")
public class UserController {
    @Resource
    private UserMapper userMapper;


    //insert
    @PostMapping()
    public int insertUser(@RequestBody User user) {
        int insert = userMapper.insert(user);
        return insert;
    }

    @GetMapping("/get/{id}")
    public List<User> getUser(@PathVariable("id") Integer id) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        List<User> list = userMapper.selectList(wrapper);
        return list;
    }

    @PostMapping("/page")
    public Map getPageUser(@RequestBody MyPage page) {
        Page<User> page1 = new Page<>(page.getPage(),page.getSize());
        Page<User> userPage = userMapper.selectPage(page1, null);
        Map<String,Object> mp = new HashMap<>();
        mp.put("data",userPage);
        return mp;
    }

}
